<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <META http-equiv="Pragma" content="no-cache" />
    <META http-equiv="Cache-Control" content="no-cache" />
    <META http-equiv="Expires" content="0" />
    
<title>选择人员</title>
<base target="_self" />

<script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
</head>
<script type="text/javascript">
    function RtValue(rtstr)
    {
        window.returnValue=rtstr;
        window.close();
    }
    
    function addSelectValue()
    {
        var accounts = window.frames["frmSelectPeople"].document.getElementsByName("selAccount");
        var _accounts, accountOptn, orgList;
        
        orgList = document.getElementById("orgListBox");
        if(accounts != null && typeof(accounts) != "undefined")
        {
            for(var i = 0; i < accounts.length; i++)
            {
                if(accounts[i].checked)
                {
                    _accounts = accounts[i].value.split("|");
                    if(checkIfHaveAccount(_accounts[0], orgList))
                    {
                        continue; //已存在列表中
                    }
                    accountOptn = document.createElement("option");
                    accountOptn.value = _accounts[0];
                    accountOptn.text = _accounts[1];
                    
                    orgList.add(accountOptn);                     
                }
            }
        }
    }
    
    function checkIfHaveAccount(val, orgListSel)
    {
        for(var i = 0; i < orgListSel.options.length; i++)
        {
          if(orgListSel.options[i].value == val)
          {
            return true;
          }
        }
        return false;
    }
    
    function removeSelectValue()
    {
        if($("#orgListBox").find("option:selected").length == 0) { 
        	alert("请选择所要移除的姓名！"); 
        } else { 
        	$("#orgListBox").find("option:selected").remove(); 
        }
    }
    
    function clearSelectValue()
    {
        $("#orgListBox").empty();
    }
    
    function confrimSelectValue()
    {
        var obj = new Object();
        var orgList = document.getElementById("orgListBox");
        var _val="";
        var _txt="";
        for(var i=0;i < orgList.options.length;i++)
        {
            _val += orgList.options[i].value + ",";
            _txt += orgList.options[i].text + ",";
        }
        
        _val = _val.substr(0, _val.length - 1);
        _txt = _txt.substr(0, _txt.length - 1);
        obj.id = _val;
        obj.name = _txt;
        if(orgList.options.length <= 0)
        {
            obj = null;
        }
        
        window.returnValue = obj;
        window.close();
    }
    
</script>

<body bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0">
<form id="fm1">

  <table height="400" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="220">
            <iframe name="frmSelectPeople" width="600" height="600" src="/SCMDB/employeeAction!findEmployeeList.action" frameborder="0"></iframe>
         </td>
        <td valign="middle">
        <table width="79" border="0">
          <tr>
            <td align="center"><input type="button" name="btnAdd" value="添加" class="btn" onclick="addSelectValue();" /></td>
          </tr>
          <tr>
            <td align="center"><input type="button" name="btnRemonve" value="移除" class="btn" onclick="removeSelectValue();" /></td>
          </tr>
          <tr>
            <td align="center"><input type="button" name="btnClear" value="清空" class="btn" onclick="clearSelectValue();" /></td>
          </tr>
          <tr>
          	<td align="center"><input type="button" name="confirm" class="btn" value="确定" onclick="javascript:confrimSelectValue();" /></td>
          </tr>
          <tr>
          	<td align="center"><input type="button" name="canel" class="btn" value="取消" onclick="javascript:window.close();" /></td>
          </tr>
        </table>
        </td>
        <td width="150" >
             <select size="10" id="orgListBox" name="orgListBox" style="height:520px;width:160px;" multiple="multiple"></select>
        </td>
      </tr>
</table>

    </form>
</body>
</html>
